<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="数据类型" prop="dataType">
        <el-select v-model="queryParams.dataType" placeholder="请选择数据类型" clearable size="small">
          <el-option
            v-for="item in dataTypeOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="访问时间" prop="times">
        <el-input
          v-model="queryParams.times"
          placeholder="请输入访问times"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="访问轮次" prop="requestNum">
        <el-input
          v-model="queryParams.requestNum"
          placeholder="请输入访问轮次"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['modules:dataRecord:add']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['modules:dataRecord:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['modules:dataRecord:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['modules:dataRecord:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="dataRecordList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键ID" align="center" prop="dataId" v-if="false"/>
      <el-table-column label="数据类型" align="center" prop="dataType" >
        <template slot-scope="scope">
          <span>{{ dataTypeName(scope.row.dataType) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="应报站点数" align="center" prop="shouldReportStationNum" />
      <el-table-column label="及时站点数" align="center" prop="inTimeStationNum" />
      <el-table-column label="实报站点数" align="center" prop="realReportStationNum" />
      <el-table-column label="缺报站点数" align="center" prop="missReportStationNum" />
      <el-table-column label="超时站点数" align="center" prop="overTimeStationNum" />
      <el-table-column label="及时率" align="center" prop="inTimeRate" />
      <el-table-column label="实报率" align="center" prop="realRate" />
      <el-table-column label="缺报率" align="center" prop="missRate" />
      <el-table-column label="超时率" align="center" prop="overTimeRate" />
      <el-table-column label="修改时间" align="center" prop="updateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="数据创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>

<!--      <el-table-column label="实报站点" align="center" prop="realReportStationIdCList" />-->
      <el-table-column label="缺报站点" align="center" prop="missReportStationIdCList" />
      <el-table-column label="超时站点" align="center" prop="overTimeStationIdCList" />
      <el-table-column label="访问times" align="center" prop="times" />
      <el-table-column label="访问轮次" align="center" prop="requestNum" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="handleUpdate(scope.row)"-->
<!--            v-hasPermi="['modules:dataRecord:edit']"-->
<!--          >修改</el-button>-->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['modules:dataRecord:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改数据记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="数据类型 1-地面要素 2-站点状态 " prop="dataType">
          <el-select v-model="form.dataType" placeholder="请选择数据类型 1-地面要素 2-站点状态 ">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="应报站点数" prop="shouldReportStationNum">
          <el-input v-model="form.shouldReportStationNum" placeholder="请输入应报站点数" />
        </el-form-item>
        <el-form-item label="实报站点数" prop="realReportStationNum">
          <el-input v-model="form.realReportStationNum" placeholder="请输入实报站点数" />
        </el-form-item>
        <el-form-item label="缺报站点数" prop="missReportStationNum">
          <el-input v-model="form.missReportStationNum" placeholder="请输入缺报站点数" />
        </el-form-item>
        <el-form-item label="超时站点数" prop="overTimeStationNum">
          <el-input v-model="form.overTimeStationNum" placeholder="请输入超时站点数" />
        </el-form-item>
        <el-form-item label="实报站点  多个以逗号隔开" prop="realReportStationIdCList">
          <el-input v-model="form.realReportStationIdCList" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="缺报站点  多个以逗号隔开" prop="missReportStationIdCList">
          <el-input v-model="form.missReportStationIdCList" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="超时站点  多个以逗号隔开" prop="overTimeStationIdCList">
          <el-input v-model="form.overTimeStationIdCList" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="访问times" prop="times">
          <el-input v-model="form.times" placeholder="请输入访问times" />
        </el-form-item>
        <el-form-item label="访问轮次" prop="requestNum">
          <el-input v-model="form.requestNum" placeholder="请输入访问轮次" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listDataRecord, getDataRecord, delDataRecord, addDataRecord, updateDataRecord, exportDataRecord } from "@/api/modules/dataRecord";

export default {
  name: "DataRecord",
  components: {
  },
  data() {
    return {
      // 数据得类型选择
      dataTypeOptions:[
        {
          label:'地面要素',
          value:'1'
        },
        {
          label:'站点状态',
          value:'2'
        },
      ],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 数据记录表格数据
      dataRecordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        dataType: undefined,
        shouldReportStationNum: undefined,
        realReportStationNum: undefined,
        missReportStationNum: undefined,
        overTimeStationNum: undefined,
        realReportStationIdCList: undefined,
        missReportStationIdCList: undefined,
        overTimeStationIdCList: undefined,
        times: undefined,
        requestNum: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 回显数据类型名称 */
    dataTypeName(dataType){
      let name = '';
      this.dataTypeOptions.forEach(normal =>{
        if(normal.value === dataType){
          name = normal.label;
        }
      });
      return name;
    },
    /** 查询数据记录列表 */
    getList() {
      this.loading = true;
      listDataRecord(this.queryParams).then(response => {
        this.dataRecordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        dataId: undefined,
        dataType: undefined,
        updateTime: undefined,
        createTime: undefined,
        shouldReportStationNum: undefined,
        realReportStationNum: undefined,
        missReportStationNum: undefined,
        overTimeStationNum: undefined,
        realReportStationIdCList: undefined,
        missReportStationIdCList: undefined,
        overTimeStationIdCList: undefined,
        times: undefined,
        requestNum: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.dataId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加数据记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const dataId = row.dataId || this.ids
      getDataRecord(dataId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改数据记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.dataId != null) {
            updateDataRecord(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDataRecord(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const dataIds = row.dataId || this.ids;
      this.$confirm('是否确认删除数据记录编号为"' + dataIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delDataRecord(dataIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有数据记录数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportDataRecord(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
